package com.szt.sy.config.mybatis.plus;

import java.util.Date;

import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.mapper.MetaObjectHandler;

/****
 * 自定义公共字段填充
 *
 * @author wwy
 *
 */
@Component
public class CustomMetaObjectHandler extends MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		// 更多查看源码测试用例
		Object addDate = getFieldValByName("addDate", metaObject);
		if (addDate == null) {
			setFieldValByName("addDate", new Date(), metaObject);
		}
		Object version = getFieldValByName("version", metaObject);
		if (version == null) {
			setFieldValByName("version", 1L, metaObject);
		}
	}

	@Override
	public void updateFill(MetaObject metaObject) {

	}

}